package com.ruoyi.web.controller.fire;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.fire.domain.FireCase;
import com.ruoyi.fire.service.IFireCaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 火灾案件Controller
 * 
 * @author ruoyi
 * @date 2023-06-13
 */
@RestController
@RequestMapping("/fire/case")
public class FireCaseController extends BaseController
{
    @Autowired
    private IFireCaseService fireCaseService;

    /**
     * 查询火灾案件列表
     */
    @PreAuthorize("@ss.hasPermi('fire:case:list')")
    @GetMapping("/list")
    public TableDataInfo list(FireCase fireCase)
    {
        startPage();
        List<FireCase> list = fireCaseService.selectFireCaseList(fireCase);
        return getDataTable(list);
    }

    /**
     * 导出火灾案件列表
     */
    @PreAuthorize("@ss.hasPermi('fire:case:export')")
    @Log(title = "火灾案件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FireCase fireCase)
    {
        List<FireCase> list = fireCaseService.selectFireCaseList(fireCase);
        ExcelUtil<FireCase> util = new ExcelUtil<FireCase>(FireCase.class);
        util.exportExcel(response, list, "火灾案件数据");
    }

    /**
     * 获取火灾案件详细信息
     */
    @PreAuthorize("@ss.hasPermi('fire:case:query')")
    @GetMapping(value = "/{uId}")
    public AjaxResult getInfo(@PathVariable("uId") Long uId)
    {
        return success(fireCaseService.selectFireCaseByUId(uId));
    }

    /**
     * 新增火灾案件
     */
    @PreAuthorize("@ss.hasPermi('fire:case:add')")
    @Log(title = "火灾案件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FireCase fireCase)
    {
        return toAjax(fireCaseService.insertFireCase(fireCase));
    }

    /**
     * 修改火灾案件
     */
    @PreAuthorize("@ss.hasPermi('fire:case:edit')")
    @Log(title = "火灾案件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FireCase fireCase)
    {
        return toAjax(fireCaseService.updateFireCase(fireCase));
    }

    /**
     * 删除火灾案件
     */
    @PreAuthorize("@ss.hasPermi('fire:case:remove')")
    @Log(title = "火灾案件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{uIds}")
    public AjaxResult remove(@PathVariable Long[] uIds)
    {
        return toAjax(fireCaseService.deleteFireCaseByUIds(uIds));
    }
}
